package com.ding.easycontroller.file.impl;

import com.ding.easycontroller.work.Script;
import org.jdom.Element;


//服务于脚本
class ScriptFile {

    static void scriptToElement(Script script, Element root) {

        //id
        Element id = new Element("id");
        id.setText(script.getId());
        root.getChildren().add(id);


        //脚本
        Element js = new Element("js");
        js.setText(script.getJs());
        root.getChildren().add(js);

        //类型
        Element type = new Element("type");
        type.setText(script.getType());
        root.getChildren().add(type);


        //描述
        if (script.getDescription() != null) {
            Element element = new Element("description");
            element.setText(script.getDescription());
            root.getChildren().add(element);
        }

    }

    static void elementToScript(Element root, Script script) {

        script.setId(root.getChild("id").getText());
        script.setType(root.getChild("type").getText());
        script.setJs(root.getChild("js").getText());

        Element description = root.getChild("description");
        if (description != null && description.getText() != null) {
            script.setDescription(description.getText());
        }

    }

}
